//
// Created by lihengliu on 2023/3/4.
//

#ifndef JNIDEMO_JNI_HELPER_H
#define JNIDEMO_JNI_HELPER_H
#include <jni.h>
#include <string>

namespace clu {
    typedef struct _JniMethodInfo {
        JNIEnv *env;
        jclass classID;
        jmethodID methodID;
    } JniMethodInfo;

    class JniHelper {
    public:
        //获取java虚拟机实例
        static JavaVM *getJavaVM();

        //设置java虚拟机实例
        static void setJavaVM(JavaVM *javaVM);

        //获取java虚拟机环境
        static bool getJNIEnv(JNIEnv **pEnv);

        //绑定java虚拟机到当前线程
        static bool startJavaVMAttachCurrentThread();

        //停止java虚拟机到当前线程
        static void stopJavaVMAttachCurrentThread();

        //获取jclass
        static jclass getClassID(const char *className, JNIEnv *env);

        //获取静态方法信息
        static bool getStaticMethodInfo(JniMethodInfo &methodInfo, const char *className,
                                        const char *methodName, const char *paramCode);

        //获取非静态方法信息
        static bool getMethodInfo(JniMethodInfo &methodInfo, const char *className,
                                  const char *methodName, const char *paramCode);

    private:
        static JavaVM *javaVm;
    };
}

#endif //JNIDEMO_JNI_HELPER_H
